﻿using SnailInfo.ConvertExtension.Enums;
using System;
using System.Collections.Generic;
using System.Text;

/********************************************
* 公司名称：
* 创 建 人：程飞航-JCXC220033
* 创建日期：2025/9/29 14:30:45
* 说    明：
* 版    本：V0.0.0.1
********************************************/
namespace SnailInfo.ConvertExtension
{
    public static class RandomExtension
    {
        private static char[] random34 = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        private static char[] random36 = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        private static char[] random58 = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        private static char[] random62 = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };

        private static char[] random24 = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

        private static char[] numberchar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        /// <summary>
        /// Generate random string 
        /// </summary>
        /// <param name="randomType">random type</param>
        /// <param name="iLength">string length of you want</param>
        /// <returns>string</returns>
        public static string Generate(this RandomType randomType, int iLength)
        {
            Random random = new Random();
            StringBuilder sb = new StringBuilder();
            char[] chars;
            switch (randomType) {
                case RandomType.Char62:
                    chars = random62;
                    break;
                case RandomType.Char34:
                    chars = random34;
                    break;
                case RandomType.Char58:
                    chars = random58;
                    break;
                case RandomType.Char24:
                    chars = random24;
                    break;
                case RandomType.Char36:
                    chars = random36;
                    break;
                case RandomType.Number:
                    chars = numberchar;
                    break;
                default:
                    chars = random62;
                    break;
            }
            for (int i = 0; i < iLength; i++) {
                int iIndex = random.Next(0, (int)randomType);
                sb.Append(chars[iIndex]);
            }

            return sb.ToString();
        }
    }
}
